

let Action = require('./action');

class MoveBy extends Action{

    constructor(d,dx,dy) {
        super();
        this.duration = d;
        this._dx = dx;
        this._dy = dy;
    }

    start() {
        super.start();
        this._startX = this.target.x;
        this._startY = this.target.y;
    }

    update(t) {
        if(this.target.visible && this.target.enabled){
            this.target.x = this._startX + t * this._dx;
            this.target.y = this._startY + t * this._dy;
        }
    }
}

class MoveTo extends MoveBy{
    constructor(d,dx,dy) {
        super(d,dx,dy);
    }
    start() {
        super.start();
        this._deltaX = this._dx - this._startX;
        this._deltaY = this._dy - this._startY;
    }
    update(t) {
        if(this.target.visible && this.target.enabled){
            this.target.x = this._startX + t * this._deltaX;
            this.target.y = this._startY + t * this._deltaY;
        }
    }
}

module.exports = {
    MoveBy:MoveBy,
    MoveTo:MoveTo,
};